package com.example.kafkalearn.producer;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * 消费拦截器发送示例
 * @author 何昌杰
 */
public class Producer6Start {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Properties properties = new Properties();
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        // 重试次数
        properties.put(ProducerConfig.RETRIES_CONFIG, 10);
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put("bootstrap.servers", "10.51.34.61:9092");

        KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
        ProducerRecord<String, String> record = new ProducerRecord<>("harris", "kafka-demo", "hello harris!!!!");
        ProducerRecord<String, String> record2 = new ProducerRecord<>("harris", 0, System.currentTimeMillis() - 10 * 1000,"kafka-demo","hello harris expire!!!!");
        producer.send(record);
        producer.send(record2);
        producer.close();
    }
}
